home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / cool / ge_cool.lha / GE_COOL2.1 / src / Range / Base_Range.C next >
C/C++ Source or Header  |  1992-04-13  |  4KB  |  82 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12. //
  13. // Created: MBN 09/01/89 -- Initial design and implementation
  14. // Updated: LGO 12/04/89 -- Efficiency re-write
  15. // Updated: MJF 03/12/90 -- Added group names to RAISE
  16. // Updated: MJF 07/31/90 -- Added terse print
  17. // Updated: DLS 03/27/91 -- New lite version
  18. //
  19. // The  CoolRange class implements non-type specific  common  functionality for the
  20. // parameterized CoolRange<Type>. In this manner, code replication is  reduced. The
  21. // CoolRange<Type> class  supports  arbitrary user-defined ranges  for  a  type  of
  22. // object or built-in data type. This allows other higher level data structures
  23. // such as Vector to be parameterized over a  range of values  for some type so
  24. // that   the  programmer  does  not have  to add  bounds  checking code to the
  25. // application.  A Vector of positive integers, for  example, would be  easy to
  26. // declare, facilitating bounds checking restricted to the code that implements
  27. // the type, not the vector.
  28. //
  29. // The inclusive upper and lower bounds for the range are stored in two private
  30. // static data slots for the class as a  whole.  In addition, a single instance
  31. // private  data slot holds the instance  value. There are  three constructors.
  32. // The first is a simple  empty constructor. The second  is a constructor  that
  33. // also accepts an  initial value. And the third  is a constructor that takes a
  34. // reference to another CoolRange<Type> object and copies the value.
  35. //
  36. // All methods are implemented as  small inline  functions to provide efficient
  37. // encapsulation of objects, including built-in types such as  int. Methods are
  38. // provided to set and get the lower and upper bounds for the  class as a whole
  39. // and set the  value of the  instance data  slot. Assignment of  one object to
  40. // another is supported by the overloaded operator=  methods.  Operator() is an
  41. // inline  method to  return  the value of  the  instance  object.  Finally, an
  42. // implicit conversion from a CoolRange<Type> object to a Type value is provided to
  43. // allow for mixed expressions.
  44. //
  45.  
  46. #ifndef BASE_RANGEH            // If no CoolRange class
  47. #include <cool/Base_Range.h>        // Include header file
  48. #endif
  49.  
  50.  
  51. // set_low_error -- Raise exception for CoolRange::set() constructor
  52. // Input:           Character string indicating type and value
  53. // Output:          None
  54.  
  55. void CoolRange::set_low_error (const char* type, const char* lbound, const char* hbound,
  56.  const char* value) const {
  57.    //RAISE (Error, SYM(CoolRange), SYM(Under_Lower_Limit),
  58.    printf ("CoolRange<%s,%s,%s>::set(): Value %s less than lower-limit", type, lbound, hbound, value);
  59. }
  60.  
  61.  
  62. // set_upper_error -- Raise exception for CoolRange::set() constructor
  63. // Input:             Character string indicating type and value
  64. // Output:            None
  65.  
  66. void CoolRange::set_upper_error (const char* type, const char* lbound, const char* hbound, const char* value) const {
  67.   //RAISE (Error, SYM(CoolRange), SYM(Over_Upper_Limit),
  68.   printf ("CoolRange<%s,%s,%s>::set(): Value %s greater than upper-limit", type, lbound, hbound, value);
  69. }
  70.  
  71.  
  72. // print --  terse print function for CoolRange
  73. // Input:    reference to output stream
  74. // Output:   none
  75.  
  76. void CoolRange::print(ostream& os) {
  77.   os << form("/* CoolRange %lx */", (long) this);
  78. }
  79.  
  80.  
  81.  
  82.